class mySingleton {
    private static mySingleton instance;

    private mySingleton() {

    }

    public mySingleton getInstance() {
        //减少加锁开销
        if (instance == null) {
            synchronized (this) {
                //保证实例化过程原子性
                if (instance == null) {
                    instance = new mySingleton();
                }
            }
        }
        return instance;
    }
}

class mySingletonLazy2 {
    private volatile static mySingletonLazy2 instance = new mySingletonLazy2();

    public mySingletonLazy2 getInstance() {
        return instance;
    }

    private mySingletonLazy2() {

    }
}
public class Demo1 {

}
